/*
Copyright (C) 2011  Christoph Schnack, Berlin (Germany)

This file is part of Tribuit.

    Tribuit is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Tribuit is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Tribuit.  If not, see <http://www.gnu.org/licenses/>.
*/
package Wordcheck;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Vector;

import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;

import Storage.Meaning;
import Storage.TermClass;
import Settings.*;
/**
 * @author Christoph Schnack
 *
 */
public class TestListener implements ActionListener{
	InterrogationPanel iPanel;
	Wordcheck WCK;
	Settings SET;
	Language LANG;
	public TestListener(Wordcheck wck, Settings set){
		WCK = wck;
		SET = set;
		LANG = set.getLanguage();
	}
	public void actionPerformed(ActionEvent e){
		iPanel = WCK.getInputPanel();
		if(!iPanel.checkInputs()){
			if(WCK.getTestmodus()){
				WCK.jukeBoxPlayWrong();
				WCK.addWrongAnswer(iPanel.getWrongAnswerString());
				WCK.addWrongWord();
				WCK.increaseWrongStatistic();
				SwingUtilities.invokeLater(new Runnable(){
					public void run(){
						WCK.testNext();
					}
				});
			}
			else{
				SwingUtilities.invokeLater(new Runnable(){
					public void run(){
						WCK.jukeBoxPlayWrong();
						JOptionPane.showMessageDialog(WCK.getFrame(),iPanel.getErrorMessage(),LANG.getAttention(),JOptionPane.WARNING_MESSAGE);
						iPanel.grabFocusFaultyComponent();
					}
				});
			}
		}
		else WCK.testCorrect();
	}
}
